#!/usr/bin/python
# -*- coding: utf-8 -*-

##
 # Copyright 2009 Caio Souza
 # This file is part of Rpyg.
 #
 # Rpyg is free software: you can redistribute it and/or modify
 # it under the terms of the GNU General Public License as published by
 # the Free Software Foundation, either version 3 of the License, or
 # (at your option) any later version.
 #
 # Rpyg is distributed in the hope that it will be useful,
 # but WITHOUT ANY WARRANTY; without even the implied warranty of
 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 # GNU General Public License for more details.
 #
 # You should have received a copy of the GNU General Public License
 # along with Rpyg. If not, see <http://www.gnu.org/licenses/>.
 ##

KEY_NORTH, KEY_EAST, KEY_SOUTH, KEY_WEST, KEY_ACT = range (1, 6)
'''Constantes do controle.'''

def incTile (i, j, key):
    if key == KEY_NORTH: return i, j - 1
    if key == KEY_SOUTH: return i, j + 1
    if key == KEY_WEST: return i - 1, j
    if key == KEY_EAST: return i + 1, j
    return i, j
    
def save (obj, filename):
    '''Salva o objeto em um arquivo'''
    
    output = filename
    if not isinstance (filename, file): output = open (output, 'wb')
    pickle.dump (obj, output)
    output.close ()
    
def load (obj, filename):
    '''Carrega o objeto a partir de um arquivo'''
    
    input = filename
    if not isinstance (filename, file): input = open (input, 'rb')
    obj = pickle.load (obj, input)
    input.close ()
    return obj
    